package com.qpkj.web.controller.oms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qpkj.common.annotation.Log;
import com.qpkj.common.core.controller.BaseController;
import com.qpkj.common.core.domain.AjaxResult;
import com.qpkj.common.enums.BusinessType;
import com.qpkj.oms.domain.OmsProductNeeds;
import com.qpkj.oms.service.IOmsProductNeedsService;
import com.qpkj.common.utils.poi.ExcelUtil;
import com.qpkj.common.core.page.TableDataInfo;

/**
 * 生产所需Controller
 *
 * @author ruoyi
 * @date 2022-12-22
 */
@RestController
@RequestMapping("/oms/productneeds")
public class OmsProductNeedsController extends BaseController {
    @Autowired
    private IOmsProductNeedsService omsProductNeedsService;

    /**
     * 查询生产所需列表
     */
    @PreAuthorize("@ss.hasPermi('oms:productneeds:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsProductNeeds omsProductNeeds) {
        startPage();
        List<OmsProductNeeds> list = omsProductNeedsService.selectOmsProductNeedsList(omsProductNeeds);
        return getDataTable(list);
    }

    /**
     * 导出生产所需列表
     */
    @PreAuthorize("@ss.hasPermi('oms:productneeds:export')")
    @Log(title = "生产所需", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsProductNeeds omsProductNeeds) {
        List<OmsProductNeeds> list = omsProductNeedsService.selectOmsProductNeedsList(omsProductNeeds);
        ExcelUtil<OmsProductNeeds> util = new ExcelUtil<OmsProductNeeds>(OmsProductNeeds.class);
        util.exportExcel(response, list, "生产所需数据");
    }

    /**
     * 获取生产所需详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:productneeds:query')")
    @GetMapping(value = "/{needId}")
    public AjaxResult getInfo(@PathVariable("needId") Long needId) {
        return success(omsProductNeedsService.selectOmsProductNeedsByNeedId(needId));
    }

    /**
     * 新增生产所需
     */
    @PreAuthorize("@ss.hasPermi('oms:productneeds:add')")
    @Log(title = "生产所需", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsProductNeeds omsProductNeeds) {
        return toAjax(omsProductNeedsService.insertOmsProductNeeds(omsProductNeeds));
    }

    /**
     * 修改生产所需
     */
    @PreAuthorize("@ss.hasPermi('oms:productneeds:edit')")
    @Log(title = "生产所需", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsProductNeeds omsProductNeeds) {
        return toAjax(omsProductNeedsService.updateOmsProductNeeds(omsProductNeeds));
    }

    /**
     * 删除生产所需
     */
    @PreAuthorize("@ss.hasPermi('oms:productneeds:remove')")
    @Log(title = "生产所需", businessType = BusinessType.DELETE)
    @DeleteMapping("/{needIds}")
    public AjaxResult remove(@PathVariable Long[] needIds) {
        return toAjax(omsProductNeedsService.deleteOmsProductNeedsByNeedIds(needIds));
    }
}
